package com.xuxin.baby.popup;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ScreenUtils;
import com.lxj.xpopup.animator.PopupAnimator;
import com.lxj.xpopup.core.CenterPopupView;
import com.xuxin.baby.R;

/**
 * Created by xu_xin
 * Created on 2020/12/3 0003
 */
public class ConfirmPopup extends CenterPopupView implements View.OnClickListener {
    private String message;

    public ConfirmPopup(@NonNull Context context) {
        super(context);
    }

    public ConfirmPopup(@NonNull Context context, String message, OnConfirmListener onUpdateConfirmListener) {
        super(context);
        this.onUpdateConfirmListener = onUpdateConfirmListener;
        this.message = message;
    }

    private OnConfirmListener onUpdateConfirmListener;

    public interface OnConfirmListener {
        void onConfirm();
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.popup_confirm;
    }

    @Override
    protected void onCreate() {
        findViewById(R.id.popup_confirm_confirm).setOnClickListener(this);
        findViewById(R.id.popup_confirm_cancel).setOnClickListener(this);
        TextView popup_confirm_content = findViewById(R.id.popup_confirm_content);
        popup_confirm_content.setText(message);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.popup_confirm_confirm) {
            if (null != onUpdateConfirmListener) {
                onUpdateConfirmListener.onConfirm();
            }
            dismiss();
        } else if (id == R.id.popup_confirm_cancel) {
            dismiss();
        }
    }

    @Override
    protected int getMaxWidth() {
        return (int) (ScreenUtils.getScreenWidth() * 0.75);
    }

    @Override
    protected int getMaxHeight() {
        return (int) (ScreenUtils.getScreenWidth() * 0.75);
    }

    @Override
    protected PopupAnimator getPopupAnimator() {
        return super.getPopupAnimator();
    }

    protected int getPopupWidth() {
        return 0;
    }

    protected int getPopupHeight() {
        return 0;
    }
}